//
//  ZJMainTableViewController.swift
//  LZJweibo
//
//  Created by apple on 16/7/20.
//  Copyright © 2016年 hehe. All rights reserved.
//

import UIKit

class ZJMainTableViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewController()
    }
    
    func addChildViewController() {
        //添加子控制器
        //首页
        let homeVC = ZJHomeTableViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = ZJMessageTableViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoveryVC = ZJDiscoveryTableViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = ZJProfileTableViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    func addChildViewController(controller: UIViewController,title: String,imageName:String) {
        //设置标题和图片
        controller.title = title
        
        //设置选中时字体颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        //拼接选中图片的名称
        let selectedImagName = imageName + "_selected"
        //设置选中的图片
        controller.tabBarItem.selectedImage = UIImage(named: selectedImagName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
    }

}
